import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import time
class data_record:
    def __init__(self,Q_index,dir_index):
        '''
        param:
            Q_index:题号
            index: 自定义序号
        '''
        # self.real_time = time.time()
        self.Q_index = Q_index
        self.dir_index = dir_index
        self.data = []
    def data_dump(self):
        print("dump_data{}".format(self.Q_index))
        data_array = np.asarray(self.data)
        data_array = data_array.reshape(-1,4)
        # series1 = pd.Series(data_array,index=['t/s', 'T_in/C', 'T_out/C',"P_status"])
        # series1 = pd.Series(data_array)
        df = pd.DataFrame(data_array, columns = ['t/s', 'T_in/C', 'T_out/C',"P_status"])

        df.to_csv("{}_{}.csv".format(self.dir_index, self.Q_index))
    def data_get(self):
        # print("data_get{}".format(self.Q_index))
        data_array = np.asarray(self.data)
        data_array = data_array.reshape(-1,4)
        return data_array

    def data_append(self,t,temp_in,_temp_out,P_status):
        # self.data.append([t,temp_in,_temp_out,P_status])
        self.data.append(t)
        self.data.append(temp_in)
        self.data.append(_temp_out)
        self.data.append(P_status)
    def load_data(self,filename):
        pass
    def data_clear(self):
        self.data = []





